package com.shou.zhnfyxt.controller;


import com.shou.zhnfyxt.entity.EmailEntity;
import com.shou.zhnfyxt.entity.R;
import com.shou.zhnfyxt.service.SendEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;


@Controller
@RestController
@RequestMapping("/user/email")
public class SendEmailController {
    @Autowired
    private SendEmailService sendEmailService;

    @Value("${spring.mail.username}") //动态获取配置文件中 发送邮件的账户
    private String sendemail;

    @PostMapping("/send")
    public R<EmailEntity> sendVerifiedEmail(@RequestBody EmailEntity emailEntity){
        String email = emailEntity.getEmail();
        int yzm = new Random().nextInt(9999) % (9999 - 1000 + 1) + 1000;
        emailEntity.setVericationCode(yzm);
        sendEmailService.sendEmail(sendemail,email,"欢迎访问邮政验证码","您的验证码是"+yzm);
        return R.success(emailEntity);
    }
}
